#include "game.h"

vector<int> Game::move_Digdug(Movables &movable, const Direction &direction)
{
	//vector<vector<Object_type>>::iterator map_y_location_it;
	//vector<Object_type>::iterator map_x_location_it;

//create vector oftype int to hold return coordinate values
	vector<int> vector_with_new_loc;

	movable.set_direction(direction);

	int start_map_x_location;
	int start_map_y_location;

// return the x-location of the center of the object
	int start_movable_center_x = movable.get_x_location(); 
// return the y-location of the center of the object
	int start_movable_center_y = movable.get_y_location();
// get the coordinates and dimensions of the movable
	int start_top_of_movable = start_movable_center_y - movable.get_y_boundary();
	int start_bottom_of_movable = start_movable_center_y + movable.get_y_boundary();
	int start_LHS_of_movable = start_movable_center_x - movable.get_x_boundary();
	int start_RHS_of_movable = start_movable_center_x + movable.get_x_boundary();
	int height_of_movable = 2*movable.get_y_boundary() + 1;
	int length_of_movable = 2*movable.get_x_boundary() + 1;		

	int movable_type;
	movable_type = movable.get_object_type();


	if (movable_type == DIGDUG)
	{
		if (movable.get_direction() == UP) //!!check whether can simply compare an integer to an enumerated type
		{
			
			for (int j = start_top_of_movable - 1; j <= movable.get_speed() && j >= 0; j--)
			{
				for (int i = start_LHS_of_movable; i <= start_RHS_of_movable; i++)
				{
					if( _screen_map[i][j] == SAND)
					{					
						_screen_map[i][j] = DIGDUG;
						_screen_map[i][j - height_of_movable] = HOLE;
					}

//if DIGUG tries to move into a monster return vector containing [0,0]

					else if(_screen_map[i][j] == MONSTER)
					{
						movable.set_status(DEAD);
						vector_with_new_loc.push_back(0);
						vector_with_new_loc.push_back(0);
						return vector_with_new_loc;
						
						
					}

				}

				int final_movable_center_x = movable.get_x_location();
				int final_movable_center_y = movable.get_y_location();
				
				movable.set_location(final_movable_center_x, final_movable_center_y);

				vector_with_new_loc.push_back(final_movable_center_x);
				vector_with_new_loc.push_back(final_movable_center_y);

				return vector_with_new_loc;				

			}
			
		}

	}


	
}
